# class Preson:
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#
#     def get_name(self):
#         print("执行获取")
#         return self.name
#
#     def set_name(self,name):
#         print("执行设置")
#         if 2<=len(name)<=4:
#             self.name=name
#         else:
#             print("设置不合法")
#
#     def get_age(self):
#         print("执行年龄获取")
#         return self.age
#
#     def set_age(self,age):
#         print("执行年龄设置")
#         if 0<=age<=100:
#             self.age=age
#         else:
#             print("年龄设置不合法")
#
#     p_name = property(fget=get_name,fset=set_name)
#     p_age = property(fget=get_age,fset=set_age)
#
# p=Preson("张三",60)
# print(p.name,p.age)
#
# p.p_name ="李四"
# print(p.p_name)
#
# p.p_age = 80
# print(p.p_age)

class Preson:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    @property
    def p_name(self):
        print("执行获取")
        return self.name

    @p_name.setter
    def p_name(self,name):
        print("执行设置")
        if 2<=len(name)<=4:
            self.name=name
        else:
            print("设置不合法")

    @property
    def p_age(self):
        print("执行年龄获取")
        return self.age

    @p_age.setter
    def p_age(self,age):
        print("执行年龄设置")
        if 0<=age<=100:
            self.age=age
        else:
            print("年龄设置不合法")


p=Preson("张三",60)
print(p.age,p.name)

p.p_name = "李四"
print(p.p_name)

p.p_age = 30
print(p.p_age)